local Lua__ge = fk.CreateSkill {
  name = "Lua__ge",
  tag = { Skill.Compulsory },
}

local M = require "packages.internetMEME.record.INTTE"

-- 彁彁彁彁彁彁彁彁彁彁彁彁彁彁彁彁彁彁彁彁彁彁彁彁彁彁彁彁彁彁彁彁彁彁彁彁彁彁彁彁彁彁彁彁彁彁彁彁彁彁彁彁彁彁彁彁彁彁
Fk:loadTranslationTable {
  ["Lua__ge"] = "彁",
  ["@@ge"] = "<font color='red'>彁彁彁</font>",
  [":Lua__ge"] = "锁定技，游戏开始前，将其他角色的技能描述和技能名修改为“彁”；受到伤害的角色将武将名和图片更改至与你一致；第x个回合结束时，若场上其他角色均受到过伤害，你胜利，否则你死亡。（X为场上存活人数）",
}

Lua__ge:addEffect(fk.GamePrepared, {
  priority = 2,
  is_delay_effect = true,
  anim_type = "special",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(Lua__ge.name)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    for _, cp in ipairs(room:getOtherPlayers(player)) do
      M.removeREAllSkills(cp, room, Lua__ge.name)
      room:handleAddLoseSkills(cp, "Lua__geFUjia")
      M.restoreRERemovedSkills(cp, room, Lua__ge.name)
    end
  end,
})


Lua__ge:addEffect(fk.DamageInflicted, {
  anim_type = "special",
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(Lua__ge.name) and target:getMark("@@ge") == 0 and target ~= player
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    M.ChangeGeneral(data.to, data.to.general, "GEEEE")
    room:setPlayerMark(data.to, "@@ge", 1)
  end,
})

Lua__ge:addEffect(fk.TurnEnd, {
  anim_type = "special",
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(Lua__ge.name) and player:isAlive()
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:addPlayerMark(player, "geEND", 1)
    if player:getMark("geEND") >= #room:getAlivePlayers() then
      local n = 0
      for _, cp in ipairs(room:getOtherPlayers(player)) do
        if cp:getMark("@@ge") == 1 then
          n = n + 1
        end
      end
      if n >= #room:getOtherPlayers(player) then
        room:setTag("SkipGameRule", true)
        room:setPlayerProperty(player, "role", player.general)
        room:gameOver(player.role)
      else
        room:killPlayer({ who = player })
      end
    end
  end,
})


return Lua__ge
